#Define data file 1 and 2 on server
fname1 = "/srv/danio/joseph/6111R/6111E1/6111E1_251494010051_S01_CGH-v4.1_95_Feb07.txt"
fname2 = "/srv/danio/joseph/6111R/6111E2/6111E2_251494110033_S01_CGH-v4.1_95_Feb07.txt"
#Local data file
#fname1 = "/media/Storage/Joseph/Documents/Research/ExperimentalData/6111R/6111E1/6111E1_251494010051_S01_CGH-v4.1_95_Feb07.txt"
#fname2 = "/media/Storage/Joseph/Documents/Research/ExperimentalData/6111R/6111E2/6111E2_251494110033_S01_CGH-v4.1_95_Feb07.txt"

f1 = open(fname1)
f2 = open(fname2)

#In order to retrieve the last FeatureNum, Row, and Col numbers from the first file, read the last line of file1.
last = f1.readlines()[-1].strip()
l = last.split("\t")
print "Last Line of File1: "
print l[:4]
fnum = int(l[1])
row = int(l[2])
col = int(l[3])

#Loop through file2 line by line discarding lines until you find the second '*' discard the next two or so lines until you get to the line starting with 'DATA' then start appending the lines onto file1
count = 0

while count < 10: #test on the first 10 lines
	line = f2.readline()
	if count < 2:
		if '*' in line:
			count = count+1
	else:
		if 'DATA' in line[:10]:
			l = line.split("\t")
			fnum = fnum + 1
			if col < 456:
				col = col +1
			else:
				col = 1
				row = row +1
			l[1] = fnum
			l[2] = row
			l[3] = col
			print l[:4]
			#f1.write(line)
			count = count+1

#return the new file1

#Close files
f1.close()
f2.close()
